package ldh.im.im_app;

import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugin.common.MethodChannel;
import android.media.AudioManager;
import android.content.Context;

public class MainActivity extends FlutterActivity {

    private static final String CHANNEL = "ldh.im.im_app/microphone";
    private AudioManager audioManager;

    @Override
    public void configureFlutterEngine(FlutterEngine flutterEngine) {
        super.configureFlutterEngine(flutterEngine);
        new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), CHANNEL)
                .setMethodCallHandler(
                        (call, result) -> {
                            if (call.method.equals("setMicVolume")) {
                                float volume = call.argument("volume"); // 从0到1的浮点数，转换为适合的音量级别。
                                audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL, (int) (volume * audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL)), 0);
                                result.success("Volume set");
                            } else {
                                result.notImplemented();
                            }
                        }
                );
    }
}
